public class Leetcode {
}
//leetcode:742:寻找数组的中心下标
class Solution1 {
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        long[] f = new long[n];
        long[] g = new long[n];
        f[0] = 0;
        g[n-1] = 0;
        for(int i = 1;i < n;i++){
            f[i] = f[i-1] + nums[i-1];
        }
        for(int i = n-2;i >= 0;i--){
            g[i] = g[i+1] + nums[i+1];
        }
        for(int i = 0; i < n; i++ ){
            if(f[i] == g[i]){
                return i;
            }
        }
        return -1;
    }
}

class Solution2 {
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        int f = 0;
        int g = 0;
        for(int i = 1;i < n;i++){
            g+=nums[i];
        }
        if(f == g ){
            return 0;
        }
        for(int i = 1;i < n;i++){
            f+=nums[i-1];
            g-= nums[i];
            if(f == g){
                return i;
            }
        }
        return -1;
    }
}

//leetcode:238：除自身外数组的乘积
class Solution3 {
    public int[] productExceptSelf(int[] nums) {
        int n= nums.length;
        int[] arr = new int[n];
        int[] L = new int[n];
        int[] R = new int[n];
        L[0] = 1;
        for(int i = 1; i < n;i++){
            L[i] = L[i-1]*nums[i-1];
        }
        R[n-1] = 1;
        for(int i =n-2 ;i >= 0;i--){
            R[i] = R[i+1] * nums[i+1];
        }
        int ret = 1;
        for(int i = 0;i < n;i++){
            arr[i] = L[i]*R[i];
        }
        return arr;

    }
}